export default {
	baseHttpUri: "http://192.168.3.27:8081",
	pathUri: {
		smSend: '/sm/send',
		login: '/api/login',
		nearby: '/api/nearby',
		currentUser: '/api/currentUser',
		userTop: '/api/userTop',
		userInfo: '/api/userInfo',
		userTrend: '/api/userTrend',
		thumbsUp: '/api/thumbsUp',
		userFollow: '/api/userFollow',
		banner: '/api/banner',
		topTalk: '/api/topTalk',
		trendList: '/api/trendList',
		topicInfo: '/api/topicInfo',
		uploadFile: '/api/uploadFile',
		uploadFiles: '/api/uploadFiles',
		uploadNotCh: '/api/uploadNotCh',
		addTrend: '/api/addTrend',
		topicTrend: '/api/topicTrend',
		hotTalk: '/api/hotTalk',
		topTags: '/api/topTags',
		tagUserList: '/api/tagUserList',
		hotTags: '/api/hotTags',
		mine: '/api/mine',
		mineTrend: '/api/mineTrend',
		deleteTrend: '/api/deleteTrend',
		mineAlbum: '/api/mineAlbum',
		mineInfoVo: '/api/mineInfoVo',
		tagInfo: '/api/tagInfo',
		userHeard: '/api/userHeard',
		task: '/api/task',
		mineFollow: '/api/mineFollow',
		vipType: '/api/vipType',
		vipInfo: '/api/vipInfo',
		vip: '/api/vip',
		withdrawInfo: '/api/withdrawInfo',
		coinList: '/api/coinList',
		walletInfo: '/api/walletInfo',
		bindPay: '/api/bindPay',
		recharge: '/api/recharge',
		withdraw: '/api/withdraw',
		faceAuth: '/api/faceAuth',
		notice: '/api/notice',
		noticeList: '/api/noticeList',
		block: '/api/block',
		tipOff: '/api/tipOff',
		userConsume: '/api/userConsume',
		customer: '/api/customer',
		feedback: '/api/feedback',
		updatePhone: '/api/updatePhone',
		checkVersion: '/api/checkVersion',
		logOut: '/api/logOut',
		replenish: '/api/replenish',
	},
	dataCode: {
		OK: '000000',
		COIN_ERROR: '999897',
		WECHAT_EMPTY: '999967'
	},
	json: {
		'content-type': 'application/json'
	},
	user: "userinfo",
	auth: "authToken",
	userFriend: "userFriendList",
	customer: "customer",
	first: "first",
	authHead: () => {
		return {
			'content-type': 'application/json',
			'Authorization': `Bearer ${uni.getStorageSync('authToken')}`
		}
	},
	versionCheck(show) {
		// #ifdef APP-PLUS  
		plus.runtime.getProperty(plus.runtime.appid, widgetInfo => {
			console.log(widgetInfo);
			uni.request({
				url: this.baseHttpUri + this.pathUri.checkVersion,
				data: {
					version: widgetInfo.versionCode,
					osType: plus.os.name
				},
				header: this.authHead(),
				success: result => {
					if (result.data.code === this.dataCode.OK) {
						let data = result.data.data;
						if (data.update && data.url) {
							if (data.type === 2) {
								this.updateApp(data.url);
							} else {
								uni.showModal({
									title: "有可用更新",
									content: data.note,
									success: res => {
										if (res.confirm && !plus.os.name == "Android") {
											plus.runtime.openURL(data.url);
										} else if (res.confirm) {
											this.updateApp(data.url);
										}
									}
								});
							}
						} else {
							if (show) {
								uni.showToast({
									title: '已是最新版本无需更新',
									icon: 'none',
									success() {}
								});
							}
						}
					}
				}
			});
		});
		// #endif
	},
	updateApp(url) {
		uni.downloadFile({
			url: url,
			success: (downloadResult) => {
				if (downloadResult.statusCode === 200) {
					plus.runtime.install(downloadResult
						.tempFilePath, {
							force: false
						},
						function() {
							console.log(
								'install success...');
							plus.runtime.restart();
						},
						function(e) {
							console.error(
								'install fail...');
						});
				}
			}
		});
	},
	initCustomer() {
		let customer = uni.getStorageSync(this.customer);
		let userData = uni.getStorageSync(this.user);
		if (!customer && userData) {
			uni.request({
				url: this.baseHttpUri + this.pathUri.customer,
				header: this.authHead(),
				method: 'GET',
				success: res => {
					if (res.data.code === this.dataCode.OK) {
						let customer = {
							id: res.data.data.id,
							userId: res.data.data.accountNo,
							nickName: res.data.data.userNickname,
							avatar: res.data.data.userHeadUrl,
							isVip: false,
							messageType: 'txt',
							lastMessage: '暂无消息',
							lastTime: new Date().getTime(),
							readStatus: true,
							unreadCount: 0
						}
						uni.setStorageSync(this.customer, customer);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							success() {}
						});
					}
				},
				fail: r => {
					console.log(r);
				},
			});
		}
	}
}
